﻿using Furion.FriendlyException;

namespace Api;

/// <summary>
/// 阿里云快递
/// </summary>
public class AliyunExpress
{
    private static Dictionary<string, string> authInfo = new Dictionary<string, string>()
        {
            { "Authorization" , "APPCODE bea6b0ffcb2a4eeeb63f78d48c511c59" }
        };

    /// <summary>
    /// 获取快递公司信息
    /// </summary>
    /// <param name="code"></param>
    /// <returns></returns>
    public static async Task<dynamic> GetCompanyName(string code)
    {
        string url = $"https://qrykd.market.alicloudapi.com/lundear/expressDiscern?number={code}";

        var res = await Http.Get<dynamic>(url, authInfo);

        if (res.code == 0)
        {
            return res.data;
        }

        throw Oops.Oh(res.desc);
    }

    /// <summary>
    /// 获取快递信息
    /// </summary>
    /// <param name="code"></param>
    /// <returns></returns>
    public static async Task<dynamic> GetInfo(string code)
    {
        string url = $"https://qrykd.market.alicloudapi.com/lundear/expressTracking?number={code}";

        var res = await Http.Get<dynamic>(url, authInfo);

        if (res.code == 0)
        {
            return res.data;
        }

        throw Oops.Oh(res.desc);
    }
}

